﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2011/12/28
 */
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Luminji.Core.Data;
using Luminji.Exam.Model.Users;
using System.Data.SqlClient;
using Luminji.Infrastructure.UnitOfWork;

namespace Luminji.Exam.Infrastructure.Repositories.Users
{
    public class ExamUserRepository : SqlServerRepositoryBase<ExamUser>,
        IExamUserRepository
    {
        public ExamUserRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {

        }

        public IList<ExamUser> Find(string name)
        {
            return BuildEntitiesFromSql(
                "select * from ExamUser where UserName=@UserName",
                new SqlParameter[] { new SqlParameter("@UserName", name) });
        }

        public override void Add(ExamUser user)
        {
            RegisterTextSqlToUnitOfWork(
                "insert into ExamUser (UserName,UserKey) values (@UserName,@UserKey)",
                new SqlParameter[]{
                    new SqlParameter("@UserName", user.CurrentUserName),
                    new SqlParameter("@UserKey", user.UserKey)});
        }

        public override void Remove(ExamUser user)
        {
            RegisterTextSqlToUnitOfWork(
                "Update ExamUser (UserName,UserKey) values (@UserName,@UserKey)",
                new SqlParameter[]
                    {
                        new SqlParameter("@UserName", user.CurrentUserName),
                        new SqlParameter("@UserKey", user.UserKey)
                    });
        }

        public override IList<ExamUser> Find()
        {
            throw new NotImplementedException();
        }

        public override ExamUser Find(object key)
        {
            throw new NotImplementedException();
        }
    }
}
